package edu.ynmd.com.action;


import edu.ynmd.com.vo.BMIForm;
import edu.ynmd.com.vo.Result;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class PublicAction {
    @PostMapping("getBmiValue")
    public Result getBimValue(@RequestBody BMIForm bimForm) throws Exception{
        Float resultf=bimForm.getTz()/(bimForm.getSg()*bimForm.getSg());
        String resultstr="";

        if (resultf<18.4){
            resultstr="偏瘦";
        }else if(resultf>=18.5&&resultf<=23.9){
            resultstr="正常";
        }else if(resultf>=24&&resultf<=27.9){
            resultstr="偏胖";
        }else {
            resultstr="肥胖";
        }
        Result r=new Result();
        r.setValue(resultf);
       r.setState(resultstr);

       switch (resultstr){
           case "偏瘦":
               r.setSugguest("多吃点");
           break;
           case"正常":
               r.setSugguest("别多吃，也别少吃");
           break;
           case "偏胖":
               r.setSugguest("少吃点");
            break;
           case"肥胖":
               r.setSugguest("别吃啦");
            break;
       }
        return r;
    }
}
